<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8">
	<title>黔南民族师范学院综合教育学分认定系统</title>

	<link rel="stylesheet" href="/jquery-easyui-1.3.5/themes/icon.css" />
	<link rel="stylesheet" href="/jquery-easyui-1.3.5/themes/default/easyui.css"/>

	<script type="text/javascript" src="/jquery-easyui-1.3.5/jquery.min.js"></script>
	<script type="text/javascript" src="/jquery-easyui-1.3.5/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="/jquery-easyui-1.3.5/locale/easyui-lang-zh_CN.js"></script>
    <style type="text/css" th:inline="none">
    	form div{
    		margin:20px auto;
    		width:250px;
    		text-align:center
    	}
    	
    </style>
    <script type="text/javascript" th:inline="none">
		function verifyUsername(){
			//1.获取账号
			var username = $("#username").val();
			if(username != ""){
				//2.根据账号到数据库中查询是否有数据
				$.ajax({
					url:"/user/verifyUsername",
					type:"get",
					data:{"username":username},
					success:function(msg){
						if(msg){
							$.messager.alert('Warning','用户名：'+username+'，已经存在，请更换');
							 username.focus();
						}else{
							$.messager.show({
								title:'温馨提示',
								msg:'用户名可使用！',
								timeout:3000,
								showType:'slide'
							});
						}
					}
				});
			}

		}
    	
    	$(function(){
    		$("input[name=username]").validatebox({
    			required:true,
    			missingMessage:'请输入用户名'
    		});
    		$("input[name=truename]").validatebox({
    			required:true,
    			missingMessage:'请输入真实名'
    		});
    		$("input[name=password]").validatebox({
    			required:true,
    			missingMessage:'请输入密码'
    		});
    		
    		$('#ss').combobox({    
			    url:'/school/queryAll',
			    valueField:'id',    
			    textField:'name',
			    panelHeigth:'auto',
			    panelWidth:140,
			    width:160,
			    editable:false,
			    required:true,
			    missingMessage:'请选择所属学院'
			}); 
    		$("#ff").form("disableValidation");
    		
    		$("#btn").click(function(){
    			$("#ff").form("enableValidation");
    			//通过校验
    			if($("#ff").form("validate")){
    				$("#ff").form('submit',{
    					url:'/user/saveUser',
    					error : function(event, request, settings) {
							$.messager.alert("提示消息", "请求失败!", "info");
						},
						success : function(data) {
							parent.$("#win").window("close");
    						parent.$("iframe[title='用户管理']").get(0).contentWindow.$("#dg").datagrid("reload");
						}
					});
				}
    		});
    	});
    	
    	
    	
    </script>
  </head>
  
  <body>
  	<form id="ff" method="post">   
	    <div>   
	        <label for="username">用户名称:</label>   
	        <input type="text" id="username" name="username" onchange="verifyUsername()"/>
	    </div>   
	    <div>   
	        <label >真实姓名:</label>
	        <input type="text" name="truename" />   
	    </div> 
	    <div>   
	        <label >用户密码:</label>
	        <input type="password" name="password" />   
	    </div> 
	    <div>
	    	<label >在岗状态:</label>
	    	<input type="radio" name="status" value="true" checked="checked"/>在岗
	    	<input type="radio" name="status" value="false"/>不在岗
	    </div>
		<div>
	    	<label>所属学院:</label>
	    	<input id="ss" name="sid">
	    </div>
	    <div>
	    	<a style="text-align:center;" id="btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'">添加用户</a>  
	    </div>     
	</form>  
  </body>
</html>
